import { Component, Input, OnInit } from '@angular/core';
import { UserCacheService } from '../user-cache.service';
import { User } from 'src/app/user';

@Component({
  selector: 'app-identityc',
  templateUrl: './identityc.component.html',
  styleUrls: ['./identityc.component.css'],
  providers: [UserCacheService]
})
export class IdentitycComponent implements OnInit {

  @Input() user: User;
  constructor(private userCache: UserCacheService) {
    this.userCache.onchanged.subscribe(user => this.user = user);
   }

  ngOnInit() {
    if (this.user) {
      this.userCache.setCacheUser(this.user);
    }
  }
  refreshUser() {
    this.userCache.setCacheUser(new User(this.user.id, `test_${new Date().getMilliseconds()}`, this.user.record));
  }
}
